-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Various small improvements to prepare for transparent methods #4620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
private def paramBindingDef(name: Name, paramtp: Type, arg: Tree, | ||
bindingsBuf: mutable.ListBuffer[ValOrDefDef]): ValOrDefDef = { | ||
val argtpe = arg.tpe.dealias | ||
def isByName = paramtp.dealias.isInstanceOf[ExprType] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a val
. It is always evaluated
(flags, annots.reverse, privateWithin) | ||
} | ||
|
||
private val readAnnot: Context => Annotation = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a val and not a def?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use it as a closure everytime we read a symbol. Making it a val
avoids a lot of allocations.
super.typedApply(tree, pt) | ||
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context) = { | ||
|
||
def betaReduce(tree: Tree) = tree match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to document this method since it's non-trivial and the name is a bit vague.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought beta-reduce is as specific as it gets? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just joking. I agree the details of this should be documented.
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context) = { | ||
|
||
def betaReduce(tree: Tree) = tree match { | ||
case Apply(Select(cl @ closureDef(ddef), nme.apply), args) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the closure is a SAM type then there is no guarantee that the implement method is called apply
, in fact it's possible that apply
is a completely different method that has nothing to do with ddef
so this optimization is incorrect in general, e.g.:
trait Foo {
def apply(x: Int): Int = 42
def realApply(x: Int): Int
}
object Test {
def main(args: Array[String]): Unit = {
println(((x => x): Foo).apply(10))
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. We need to restrict this to function closures.
Use combination of Enum and Case instead.
It's useful to know something was an enum when it started, and it's necessary to pickle this when serializing untyped trees.
- Mark splices in code under -print-debug - Print owners of all definitions under -print-debug-owners
- some fixes to format docs - some refactorings for better legibility
Everything should be reflected in flags and privateWithin already.
Avoid creation of `op1` methods if tracing is not enabled.
Rely on call-by-name parameters instead. Fix "unused defs" logic so that referred-to cbn parameters are not eliminated.
Since all Mod values are now reflected in flags and privateWithin, there is no need anymore to test whether a Mod exists.
c169f27
to
cd3e7e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small comment about doc, otherwise, LGTM
@@ -563,6 +563,9 @@ object Flags { | |||
/** An inline parameter */ | |||
final val InlineParam = allOf(Inline, Param) | |||
|
|||
/** An enum case */ | |||
final val EnumCase = allOf(Enum, Case) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for Enum
needs to be updated:
/** Symbol is a Java enum */
final val Enum = commonFlag(40, "<enum>")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's done in the latest commit.
Also, polishing and new test
cd3e7e3
to
d2c19ce
Compare
* refs among the ei's directly without creating an intermediate binding. | ||
*/ | ||
def betaReduce(tree: Tree) = tree match { | ||
case Apply(Select(cl @ closureDef(ddef), nme.apply), args) if defn.isFunctionType(cl.tpe) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defn.isFunctionType(cl.tpe)
A more efficient way to check this is cl.tpt.isEmpty
Too late for this PR now, but I think we really need more tests to make sure inline behave as we think it does (to not repeat issues such as #4614). We currently only have one test in https://github.com/lampepfl/dotty/blob/master/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala but it's fairly easy to add more. |
Supersedes #4589.
This PR contains some fixes accumulated while working on inlining untyped trees. It does not contain any code to inline, nor pickle untyped trees. We are currently considering an alternative design by @gsps and @OlivierBlanvillain which would not need to do this.
Main changes:
only as carriers of positions for syntactic analysis in IDE and elsewhere.
reducing the amount of code that's generated.